// user implematation 
//

#include "user.h"
#include "mlog.h"

CUser::CUser()
{
}

CUser::~CUser()
{
    if (m_mapUser.size() > 0)
    {
        m_mapUser.erase(m_mapUser.begin(), m_mapUser.end());
    }
}

int CUser::AddUser(int uid, int fd)
{
    CMLog::Plog("CUser::AddUser, uid=%d, fd=%d", uid, fd);
    m_mapUser.insert(UserType(uid, fd));
    return 0;
}

int CUser::DeleteUser(int uid)
{
    CMLog::Plog("CUser::DeleteUser, uid=%d", uid);
    if (m_mapUser.size() < 1)
        return -1;

    std::map<int, int>::iterator it;
    it = m_mapUser.find(uid);
    m_mapUser.erase(it);
    return 1;


    it = m_mapUser.begin();
    for (; it != m_mapUser.end(); it++)
    {
        if (it->first == uid)
            m_mapUser.erase(it);
    }

    return 1;
}


int CUser::SearchUser(int uid)
{
    CMLog::Plog("CUser::SearchUser, uid = %d", uid);
    if (m_mapUser.size() < 1)
        return 0;

    std::map<int, int>::iterator it;
    it = m_mapUser.find(uid);
    return it->second;

    it = m_mapUser.begin();
    for (; it != m_mapUser.end(); it++)
    {
        if (it->first == uid)
            return it->second;
    }

    return 0;
}

int CUser::GetUserAccount()
{
    return m_mapUser.size();
}

